let system = uni.getSystemInfoSync(); // 获取系统信息
/**检查是否打开GPS功能（android）**/
export const checkOpenGPSServiceByAndroid = () => {
        if (system.platform === 'android') { // 判断平台
            var context = plus.android.importClass("android.content.Context");
            var locationManager = plus.android.importClass("android.location.LocationManager");
            var main = plus.android.runtimeMainActivity();
            var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
            if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
                uni.showModal({
                    title: '提示',
                    content: '请打开定位服务功能',
                    success(res) {
                        if (res.confirm) {
                            if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
                                var Intent = plus.android.importClass('android.content.Intent');
                                var Settings = plus.android.importClass('android.provider.Settings');
                                var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                main.startActivity(intent); // 打开系统设置GPS服务页面
                            } else {
                                console.log('GPS功能已开启');
                            }
                        }
                    }
                });
                return
            }
        }
    }
 
/* 该问题用不到下面的方法，请忽略 */
 
/**
 * 检查通知是否开启
 */
export const noticMsgTool = () => {
    //如果没有打开 则可以 去 请求打开
    if (system.platform == "ios") {
        //苹果打开对应的通知栏
        uni.showModal({
            title: "通知权限开启提醒",
            content: "您还没有开启通知权限，无法接受到消息通知，请前往设置！",
            confirmText: "去设置",
            success: function(res) {
                if (res.confirm) {
                    var app = plus.ios.invoke("UIApplication", "sharedApplication");
                    var setting = plus.ios.invoke("NSURL", "URLWithString:", "app-settings:");
                    plus.ios.invoke(app, "openURL:", setting);
                    plus.ios.deleteObject(setting);
                    plus.ios.deleteObject(app);
                }
            }
        });
    } else {
        //android打开对应的通知栏
        var main = plus.android.runtimeMainActivity();
        var pkName = main.getPackageName();
        var uid = main.getApplicationInfo().plusGetAttribute("uid");
        var Intent = plus.android.importClass('android.content.Intent');
        var Build = plus.android.importClass("android.os.Build");
        uni.showModal({
            title: "通知权限开启提醒",
            content: "您还没有开启通知权限，无法接受到消息通知，请前往设置！",
            confirmText: "去设置",
            success: function(res) {
                if (res.confirm) {
                    if (Build.VERSION.SDK_INT >= 26) {
                        var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
                        intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
                    } else if (Build.VERSION.SDK_INT >= 21) { //android 5.0-7.0  
                        var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
                        intent.putExtra("app_package", pkName);
                        intent.putExtra("app_uid", uid);
                    } else { //(<21)其他--跳转到该应用管理的详情页
                        var Settings = plus.android.importClass("android.provider.Settings");
                        var Uri = plus.android.importClass("android.net.Uri");
                        var intent = new Intent();
                        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        var uri = Uri.fromParts("package", main.getPackageName(), null);
                        intent.setData(uri);
                    }
                    // 跳转到该应用的系统通知设置页  
                    main.startActivity(intent);
 
                }
            }
        });
    }
}